package JunitTest;

public class FetchMoney {
	int MoneyNu[];

	public FetchMoney() {
		MoneyNu = new int[] { 1, 1, 1, 2, 3 };

	}

	public FetchMoney(int[] MoneyNu) {
		this.MoneyNu = MoneyNu;
	}

	public boolean fetch(int total) {
	
		// 从大到小，当前金额若大于50,且50元有余，取出（下同）
		while (total >= 50 && MoneyNu[0] > 0) {
			MoneyNu[0]--;
			total -= 50;
		}
	
		while (total >= 20 && MoneyNu[1] > 0) {
			MoneyNu[1]--;
			total -= 20;
		}

		while (total >= 10 && MoneyNu[2] > 0) {
			MoneyNu[2]--;
			total -= 10;
		}
		
		while (total >= 5 && MoneyNu[3] > 0) {
			MoneyNu[3]--;
			total -= 5;
		}

		while (total >= 1 && MoneyNu[4] > 0) {
			MoneyNu[4]--;
			total -= 1;
		}
	
		if (total == 0) {
			return true;
		} else {
			return false;
		}
	}
}
